package lm.spring.feign.support;

import com.baidu.BaiduController;
import feign.codec.ErrorDecoder;
import lm.spring.feign.support.exception.ApiJsonException;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * feign client sample main
 * @author liangming 2021-12-25 3:35
 */
@ComponentScan()
public class SampleAppMain {

    public static void main(String[] args) {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
        System.out.println(context.getBean(FeignClientsAutoConfiguration.class));
        System.out.println(context.getBean(ErrorDecoder.class));

        BaiduController baiduController = context.getBean(BaiduController.class);
        System.out.println("--------------baiduController start----------------------");
        System.out.println();
        try {
            System.out.println("Baidu success: " + baiduController.get().length());
        } catch (ApiJsonException e) {
            //处理失败信息, 后端响应状态码不是200 且 content-type为json
            System.out.println("Baidu apiJsonException: " + e.getMessage());
        } catch (Exception e) {
            //处理失败信息, 后端响应状态码不是200 且 content-type不为json
            System.out.println("Baidu exception: " + e.getMessage());
        }
        System.out.println();
        System.out.println("----------------baiduController end--------------------");

        System.out.println();
        System.out.println();

        System.out.println("--------------getErrorPage start----------------------");
        System.out.println();
        try {
            System.out.println("Baidu: " + baiduController.getErrorPage().length());
        } catch (ApiJsonException e) {
            //处理失败信息, 后端响应状态码不是200 且 content-type为json
            System.out.println("Baidu apiJsonException: " + e.getMessage());
        } catch (Exception e) {
            //处理失败信息, 后端响应状态码不是200 且 content-type不为json
            System.out.println("Baidu getErrorPage: " + e.getMessage());
        }
        System.out.println();
        System.out.println("----------------getErrorPage end--------------------");
    }
}
